home *** CD-ROM | disk | FTP | other *** search
- Path: sun.uakom.sk!news
- From: Stefan Billik <billik@sun.uniag.sk>
- Newsgroups: comp.lang.c
- Subject: Re: rand ?
- Date: Mon, 25 Mar 1996 08:16:25 -0100
- Organization: steve
- Distribution: world
- Message-ID: <31566469.1596@sun.uniag.sk>
- References: <4idjt4$4du@itsop2.its.brooklyn.cuny.edu> <314BB352.2734@ccis.com> <mjs.827088266@hubcap>
- NNTP-Posting-Host: sun.uniag.sk
- Mime-Version: 1.0
- Content-Type: text/plain; charset=iso-8859-2
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0 (X11; I; SunOS 5.4 sun4m)
-
- > #include <stdlib.h>
- >
- > >#define RANDOMIZE() srand(time(NULL)) /* time() is in time.h */
- > >main()
- > >{
- > > int i ;
- > > while(i != 0 )
- > > printf("%d\n",i = random(52));
- > >}
- >
- > > int random(int i)
- > > {
- > > double x = RAND_MAX + 1.0 ;/* RAND_MAX is defined in stdlib.h */
- > > int y ;
- > > RANDOMIZE();
- > > y = 1 + rand() * (i /x) ;
- > > return y ;
- > > }
-
- > Matthew Saltzman
- > Clemson University Math Sciences
- > mjs@clemson.edu
-
- /* HERE IS ANOTHER QUESTION: */
- I am using gcc and cc at SunOS 5.4, and I am wonder, if RAND_MAX is
- defined for each compiler differently;?
- ?Look at this:
-
- 08:10 /usr1/users/student/billik/C/# cc c/random.c
- 08:10 /usr1/users/student/billik/C/# a.out
- 478513
- 08:10 /usr1/users/student/billik/C/# gcc c/random.c
- 08:10 /usr1/users/student/billik/C/# a.out
- 15
- 08:10 /usr1/users/student/billik/C/#
-
- PS: can You help me ?
-
-
- --
- \\|// \\|//
- (o o) http://sun.uniag.sk/~billik (o o)
- -ooO-(_)-Ooo-------------------------------------------ooO-(_)-Ooo-
- billik@afnet.uniag.sk && billik@sun.uniag.sk && billik@sai.uniag.sk
- steve.
-